package com.project.service.impl;

import com.project.bean.LinkBean;
import com.project.mapper.ILinkMapper;
import com.project.service.ILinkService;
import org.apache.ibatis.session.SqlSession;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LinkServiceImpl extends BaseService implements ILinkService {
    @Override
    public void add(LinkBean link) {
        SqlSession session = this.getSession();
        ILinkMapper mapper = session.getMapper(ILinkMapper.class);
        mapper.add(link);
        session.commit();
        session.close();
    }

    @Override
    public void del(int id) {
        SqlSession session = this.getSession();
        ILinkMapper mapper = session.getMapper(ILinkMapper.class);
        mapper.del(id);
        session.commit();
        session.close();
    }

    @Override
    public void update(int id, String tel) {
        SqlSession session = this.getSession();
        ILinkMapper mapper = session.getMapper(ILinkMapper.class);
        mapper.update(id,tel);
        session.commit();
        session.close();
    }

    @Override
    public List<LinkBean> findByItem(String name, LocalDate startDate, LocalDate endDate) {
        Map map = new HashMap();
        map.put("name",name);
        map.put("startDate",startDate);
        map.put("endDate",endDate);
        SqlSession session = this.getSession();
        ILinkMapper mapper = session.getMapper(ILinkMapper.class);
        List<LinkBean> list = mapper.findByItem(map);
        session.close();
        return list;
    }

    public static void main(String[] args) {
        ILinkService service = new LinkServiceImpl();
//        service.add(new LinkBean("alice","133",LocalDate.parse("1997-06-02")));
//        service.del(7);
//        service.update(1,"110");
        System.out.println(service.findByItem("o",null,null));
    }
}
